package org.gvp.generator.core.writer.impl;

import org.gvp.generator.constant.ImportConstant;
import org.gvp.generator.core.writer.AbstractFileWriter;
import org.gvp.generator.props.CreateProps;
import org.gvp.generator.props.ProjectProps;
import org.gvp.generator.table.TableInfo;

import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * 数据层代码生成类
 */
public class ServiceFileWriter extends AbstractFileWriter {
    @Override
    public void execute(TableInfo tableInfo, ProjectProps project) {
        String upName = tableInfo.getUpperName();
        String classDefine = """
                /**
                 * %s 服务层接口
                 */
                public interface %sService extends BaseService<%s> {
                """.formatted(tableInfo.getRemark(),upName,upName);

        channel.writeNewline(project.getBasePackageImport() + project.getServicePackage() + ";");
        channel.writeEmptyLine();
        channel.writeNewline(ImportConstant.COMMON_SERVICE_IMPORT);
        channel.writeNewline(project.getEntityImport());
        channel.writeNewline(classDefine);
        channel.writeNewline("}");
    }

    @Override
    public boolean isWriterFile(CreateProps create) {
        return create.isCreateService();
    }

    @Override
    public Path getFilePath(String basePath, ProjectProps project, String fileName) {
        return Paths.get(basePath, project.getServicePackage(),fileName + "Service.java");
    }
}
